<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../../common/assets_header.jsp"/>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

	<link href="../../media/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
	<link href="../../media/css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css"/>
	<link href="../../media/css/style.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" href="../../media/css/multi-select-metro.css" />
	<link rel="shortcut icon" href="../../media/image/favicon.ico" />
	<script type="text/javascript" src="../../plugins/duallistbox/jquery.duallistbox.js"></script>
	<script src="../../media/js/bootstrap.min.js" type="text/javascript"></script>
	
	
	
	 <script type="text/javascript" src="../../media/js/jquery-migrate-1.2.1.min.js"></script>
	<script src="../../media/js/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>  
	
	<script src="../../media/js/jquery.slimscroll.min.js" type="text/javascript"></script>
	<script src="../../media/js/jquery.blockui.min.js" type="text/javascript"></script>  
	<script src="../../media/js/jquery.cookie.min.js" type="text/javascript"></script>
	<script src="../../media/js/jquery.uniform.min.js" type="text/javascript" ></script>
	<script type="text/javascript" src="../../media/js/select2.min.js"></script>
	<script type="text/javascript" src="../../media/js/wysihtml5-0.3.0.js"></script> 
	<script type="text/javascript" src="../../media/js/bootstrap-datetimepicker.js"></script>
	<script type="text/javascript" src="../../media/js/jquery.inputmask.bundle.min.js"></script>   
	<script type="text/javascript" src="../../media/js/jquery.input-ip-address-control-1.0.min.js"></script>
	<script type="text/javascript" src="../../media/js/jquery.multi-select.js"></script>   
	<script src="../../media/js/app.js"></script>
	<script src="../../media/js/form-components.js"></script> 
	
	
	<script type="text/javascript">
	$(function(){
		$("#my_multi_select1 option").each(function () {
	        var text = $(this).text();
	        if ($("#my_multi_select1 option:contains('" + text + "')").length > 1)
	            $("#my_multi_select1 option:contains('" + text + "'):gt(0)").remove();
	    })
	    
	   // ${".ms-selection"}.append("已选择模块");

	})
	
	
	
	<%-- $(function(){ 
		 $.ajax({
				type : "GET",
				url : "<%=request.getContextPath()%>/module/company/moduleInfoList",
				dataType : 'json',
				async : true,
				success : function(data) {
					var option = "";
					 data.forEach(function(moduleInfo){
						 //jQuery("<option value='"+moduleInfo.moduleInfoId+"'>"+moduleInfo.moduleName+"</option>").appendTo("#my_multi_select1")
						 option +="<option value='"+${moduleInfo.moduleInfoId}+"'>"${moduleInfo.moduleName}"</option>"
					 })
					// $("#my_multi_select1").append(option);  
			}
		})
	}); 

	 --%>
	
	</script>
	
<html>
<head>

<script type="text/javascript">



function backcompanylist(){
	
	var moduleInfoIds = $('[name="my_multi_select1[]"]').val();
	<%-- $("#companymoduleform").attr("action","<%=request.getContextPath()%>/module/companymodule/add?moduleInfoIds="+moduleInfoIds);
	$("#companymoduleform").submit(); --%>
	$.ajax({
        cache: true,
        type: "POST",
        url:"<%=request.getContextPath()%>/module/companymodule/add?moduleInfoIds="+moduleInfoIds,
        data:$('#companymoduleform').serialize(),// 你的formid
        async: false,
        error: function(request) {
        	noty({layout: 'center',text: "数据处理失败",type: 'warning', timeout: 2000 });
        },
        success: function(data) {
        	/* toAssignModuleInfoPage(data.baseCompanyInfoId,data.companyCode); */
        	noty({layout: 'center',text: "数据处理成功",type: 'warning', timeout: 2000 });
		}
    })
	
	
}

function back(){
	
		$("#companymoduleform").attr("action","<%=request.getContextPath()%>/base/company/list");
		$("#companymoduleform").submit();
	
}

</script>
</head>
<body>

			<!-- content -->	
		<div class="page-content">

			<div class="container-fluid">

				<div class="row-fluid">

					<div class="span12">


						<h3 class="page-title">

							<!--系统用户管理 <small>欢迎您，admin!</small> -->

						</h3>

						<ul class="breadcrumb">

						

							<li><a href="#"></a>企业管理<!--  <i class="icon-angle-right"> </i>-->

							</li>

							<li><a href="#">分配模块</a></li>

						</ul>



					</div>

				</div>

				<div class="portlet-body form">
					<c:if test="${success==false}">
						<div class="alert alert-failure">
							<button class="close" data-dismiss="alert"></button>
							<strong><spring:message code="failure"></spring:message>!</strong>
							${errorMsg}
						</div>
					</c:if>
					<c:if test="${success }">
						<div class="alert alert-success">
							<button class="close" data-dismiss="alert"></button>
							<strong><spring:message code="success"></spring:message>!</strong>
							<spring:message code="save success"></spring:message>
							!
						</div>
					</c:if>

					</div>

					<form method="post" class="form-horizontal" id="companymoduleform" >
					
						
						<input type="hidden" name="companyCode" id="companyCode" value="${baseCompanyInfo.companyCode }">
							<div class="container" style="background-color:white;">
								<div class="container-fluid">
									<div class="space20"></div>
										<div class="space20"></div>
			
										<div class="row-fluid">
										<div class="span12"> 
											<div class="portlet box green" style=" border-color:  #438EB9" >
												<div class="portlet-title" style=" background-color: #438EB9">
												<div class="caption"><i class="icon-reorder"></i>分配模块</div>
												<div class="tools">
												<a href="javascript:;" class="collapse"></a>
												<a href="#portlet-config" data-toggle="modal" class="config"></a>
												<a href="javascript:;" class="reload"></a>
												<a href="javascript:;" class="remove"></a>
											</div>
									</div>
								<!-- 	ms-selection -->
								<div class="portlet-body form">
								<!-- BEGIN FORM-->
								<!-- <form action="#" class="form-horizontal"> -->
									<div class="control-group">
									<label class="control-label" ></label>
									<label class="control-label" style="color:#438EB9 ;width:130px;">未分配模块</label>
									<label class="control-label" style="color:#438EB9 ;width:200px;">已分配模块</label>
										<div class="space20"></div>
									<div class="controls">
										<select multiple="multiple" id="my_multi_select1" name="my_multi_select1[]" class="demo">
											<c:forEach items="${listModuleInfos }" var="item">
												
												 <c:forEach items="${listModuleCompany }" var="moduleCompany" varStatus="" >
													
   														 <c:if test="${moduleCompany.moduleInfoId ==item.moduleInfoId}">    <!--如果 --> 
   															 <option value="${item.moduleInfoId }"  selected="selected">${item.moduleName}</option>
  														 </c:if>  
    													 
   														 
												</c:forEach> 
													
														 <option value="${item.moduleInfoId }"  >${item.moduleName}</option>
 												
										   </c:forEach>
								
										</select>
									</div>
								</div>
							
							<div class="space20"></div>
							<div class="space20"></div>
							<div class="space20"></div>
							<div class="space20"></div>
							<div class="space20"></div>
							<div class="space20"></div>
							
						</div>
						
					</div>
				</div>
				
				<div class="form-actions center">
					<div class="span2"></div>
					<div class="span2"><button type="button" class="btn btn-xs btn-primary" id="showValue" onclick="backcompanylist()">Submit</button></div>
					<div class="span2"><button type="button" class="btn btn-xs btn-primary" onclick="back();">Cancel</button></div>
					<div class="span6"></div>
				</div>
				<div class="space20"></div>
				<div class="space20"></div>
				<div class="space20"></div>
			

			</div>      
		</div>	
	</div>
</form>
</div>
</div>
<script>
		jQuery(document).ready(function() {       
		   App.init();
		   FormComponents.init();
		});
		
		
		/* $("#showValue").click(function () {
            alert($('[name="my_multi_select1[]"]').val());
        }); */
	</script>
</body>
</html>